﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class frmHuyDonHang : Form
    {
        public frmHuyDonHang()
        {
            InitializeComponent();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            if (txtMaKH.Text == "")
                MessageBox.Show("Chưa Nhập MaKH!" + MessageBoxIcon.Error);
            else
            {
                
                //KhachHangDTO khDTO = new KhachHangDTO();
               string MaKH = txtMaKH.Text.ToString();
                CTDonHangBUS ctdhBUS = new CTDonHangBUS();
                List<CTDonHangDTO> ds = new List<CTDonHangDTO>();
                ds = ctdhBUS.LietKeCTDHTheoMaKH(MaKH);
                int stt = 1;
                dgvDanhSach.Rows.Clear();
                for (int i = 0; i <= ds.Count - 1; i++)
                {
                    
                    dgvDanhSach.Rows.Add(stt, ds[i].MaDH, ds[i].MaMA, ds[i].SoLuong);
                    stt++;
                }
                
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            if (txtMaDH.Text == "")
                return;
            else
            {
                //---------------LOI TRANH CHAP-----Update_SLMA_da_huy-----------------
                MonAnBUS maBUS = new MonAnBUS();
                int d = maBUS.UpdateSLMAsaukhiHuy(txtMaDH.Text.ToString());

                if (d == 1)
                {
                    //----------------Huy_CTDH-----------------

                    CTDonHangDTO ctdhDTO = new CTDonHangDTO();
                    ctdhDTO.MaDH = txtMaDH.Text;

                    CTDonHangBUS ctdhBUS = new CTDonHangBUS();
                    int a = ctdhBUS.HuyCTDonHang(ctdhDTO);

                    //---------------Huy_LichGiao-----------------
                    LichGiaoDTO lgDTO = new LichGiaoDTO();
                    lgDTO.MaDH = txtMaDH.Text;

                    LichGiaoBUS lgBUS = new LichGiaoBUS();
                    int b = lgBUS.HuyLichGiao(lgDTO);

                    //---------------Huy_DH-----------------

                    DonHangDTO dhDTO = new DonHangDTO();
                    dhDTO.MaDH = txtMaDH.Text;

                    DonHangBUS dhBUS = new DonHangBUS();
                    int c = dhBUS.HuyDonHang(dhDTO);

                    MessageBox.Show("Hủy DH thành công ");

                }

                else
                {
                    MessageBox.Show("Hủy DH thất bại ");
                }
               

            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        

    }
}
